import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import static java.lang.Thread.sleep;

public class demo9 {
    public static void main(String[] args) throws InterruptedException {

        // 构造方法传入 10 ，表示 10 个任务
        CountDownLatch countDownLatch = new CountDownLatch(10);
        ExecutorService executorService = Executors.newFixedThreadPool(4);

        executorService.submit(()->{
            for (int i = 0; i < 10; i++) {
                System.out.println("执行任务" + i);
                try {
                    sleep(100);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("执行结束 " + i);
                countDownLatch.countDown();
            }
        });
        countDownLatch.await();
        System.out.println("所有任务结束");
        executorService.shutdown();
    }
}
